package bdz.projects.atwww.electrolux
{
	import bdz.common.events.GenericEvent;
	import bdz.projects.atwww.electrolux.ui.core.ELCoreView;
	import bdz.projects.atwww.electrolux.views.ELAnalogueView;
	import bdz.projects.atwww.electrolux.views.ELDigitalView;
	
	import flash.display.MovieClip;
	import flash.display.StageAlign;
	import flash.display.StageDisplayState;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.ui.Mouse;
	
	import gs.TweenMax;
	import gs.easing.Strong;

	public class ELSite extends MovieClip {
		
		private var analogueView:ELAnalogueView;
		private var digitalView:ELDigitalView;
		private var _header:MovieClip;
		private var _previous:ELCoreView;
		public function ELSite() {
			super();
			addEventListener(Event.ADDED_TO_STAGE, initializeComponent);
		}
		private function clearPrevious():void{
			if(_previous){
				var nref:ELCoreView = _previous;
				TweenMax.to(nref, 1, {x:-1650, ease:Strong.easeInOut, onComplete:removeChild, onCompleteParams:[nref]});
			}
		}
		private function onStartDigital(evt:GenericEvent):void{
			clearPrevious();
			digitalView = new DigitalView();
			addChild(digitalView);
			digitalView.y = 100;
			digitalView.x = 1650;
			TweenMax.to(digitalView, 1, {x:-8, ease:Strong.easeInOut});
			_previous = digitalView;
		}
		private function onStartAnalogue(evt:GenericEvent):void{
			clearPrevious();
			analogueView = new AnalogueView();
			addChild(analogueView);
			analogueView.y = 100;
			analogueView.x = 1650;
			TweenMax.to(analogueView, 1, {x:-8, ease:Strong.easeInOut});
			_previous = analogueView;
			
		}
		private function onStageResize(evt:Event):void{
			if(stage.displayState == StageDisplayState.FULL_SCREEN){
				Mouse.hide();
			}else{
				Mouse.show();
			}
		}
		private function initializeComponent(evt:Event):void{
			
			
			_header = this["header"];
			_header.addEventListener("startDigital", onStartDigital);
			_header.addEventListener("startAnalogue", onStartAnalogue);
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP;
			stage.addEventListener(Event.RESIZE, onStageResize);
		}
		
	}
}